package reflect;

import java.lang.reflect.Field;
/**
 * 暴力反射对String的破坏
 */
public class ReflectDemo9 {
    public static void main(String[] args) throws Exception {
        /*
        s1zhege String对象内部
        private final char[] value = {'h','e','l','l','o'};
         */
        String s1 = "hello";
        System.out.println("s1:"+s1);
        String s2 = "hello";
        System.out.println("s2:"+s2);
        System.out.println(s1==s2);
        String s3 = "hello";
        System.out.println("s3:"+s3);
        System.out.println(s1==s3);

        Class cls = Person.class;
        Field field = cls.getDeclaredField("value");
        //打开访问权限，对于属性而言，如果它是final的也不好使，依然可以改变它的值
        field.setAccessible(true);
        /*
            s1这个String对象内部
            private final char[] value = {'w','o','r','l','d'}
         */
        field.set(s1, new char[]{'w','o','r','l','d'});
        System.out.println("s1:"+s1);
        System.out.println("s2:"+s2);
        System.out.println("s3:"+s3);

        String  s4 = "hello";
        System.out.println("s4:"+s4);
    }
}
